<template>
  <div class="login-page">
    <div class="form-container">
      <el-card class="login-card" shadow="hover">
        <h3 class="login-title">用户登录</h3>
        <el-form :model="form" :rules="rules" class="login" label-width="80px">
          <el-form-item label="账号" prop="username">
            <el-input v-model="form.username" placeholder="请输入用户名" clearable></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="form.password" placeholder="请输入密码" show-password></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script lang="ts" setup>
import {reactive} from 'vue'
import {FormRules} from "element-plus";

const form = reactive({
  username: '',
  password: ''
})

const rules = reactive<FormRules>({
  username: [
    {required: true, message: '请输入用户名', trigger: 'blur'},
    {min: 6, max: 20, message: '用户名长度为6-20之间', trigger: 'blur'},
  ],
  password: [
    {required: true, message: '请输入密码', trigger: 'blur'},
    {min: 6, max: 20, message: '密码长度为6-20之间', trigger: 'blur'},
  ]
})

const onSubmit = () => {
  console.log('submit!')
}
</script>

<style scoped>
.login-page {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-card {
  width: 400px;
  padding: 20px;
}

.login-title {
  text-align: center;
  margin-bottom: 20px;
}

.form-container {
  width: 100%;
  max-width: 600px;
}
</style>